use strict;


=head1 NAME

  RTx::AssetTracker::Group -- Class Description
 
=head1 SYNOPSIS

  use RTx::AssetTracker::Group

=head1 DESCRIPTION


=head1 METHODS

=cut

package RTx::AssetTracker::Group;

use vars qw( @ISA );
@ISA= qw(RT::Group);

# {{{ sub LoadAssetRoleGroup

=head2 LoadAssetRoleGroup  { Asset => ASSET_ID, Type => TYPE }

Loads a asset group from the database.

Takes a param hash with 2 parameters:

    Asset is the AssetId we're curious about
    Type is the type of Group we're trying to load:
        Requestor, Cc, AdminCc, Owner

=cut

sub LoadAssetRoleGroup {
    my $self       = shift;
    my %args = (Asset => '0',
                Type => undef,
                @_);
        $self->LoadByCols( Domain => 'RTx::AssetTracker::Asset-Role',
                           Instance =>$args{'Asset'},
                           Type => $args{'Type'}
                           );
}

# }}}

# {{{ CreateRoleGroup

=head2 CreateRoleGroup { Domain => DOMAIN, Type =>  TYPE, Instance => ID }

A helper subroutine which creates an asset group.
Type is one of ( "Admin" || "Owner")
Domain is one of (RTx::AssetTracker::Asset-Role || RTx::AssetTracker::Type-Role)
Instance is the id of the asset or type in question

This routine expects to be called from {Asset||Type}->CreateAssetGroups _inside of a transaction_

Returns a tuple of (Id, Message).  If id is 0, the create failed

=cut

sub CreateRoleGroup {
    my $self = shift;
    my %args = ( Instance => undef,
                 Type     => undef,
                 Domain   => undef,
                 @_ );
    unless ( $args{'Type'} =~ /^(?:Owner|Admin)$/ ) {
        return ( 0, $self->loc("Invalid Group Type") );
    }


    return ( $self->_Create( Domain            => $args{'Domain'},
                             Instance          => $args{'Instance'},
                             Type              => $args{'Type'},
                             InsideTransaction => 1 ) );
}

# }}}

# {{{ sub LoadTypeRoleGroup

=head2 LoadTypeRoleGroup  { Type => Type_ID, Type => TYPE }

Loads a Type group from the database.

Takes a param hash with 2 parameters:

    Type is the TypeId we're curious about
    Type is the type of Group we're trying to load:
        Requestor, Cc, AdminCc, Owner

=cut

sub LoadTypeRoleGroup {
    my $self       = shift;
    my %args = (AssetType => undef,
                Type => undef,
                @_);
        $self->LoadByCols( Domain => 'RTx::AssetTracker::Type-Role',
                           Instance =>$args{'AssetType'},
                           Type => $args{'Type'}
                           );
}

# }}}




1;
